package com.test;

import java.io.File;
import java.nio.file.Path;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by frinder on 2017/5/18.
 */
public class PathDemo {

    public static void main(String[] args) {
        String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        System.out.println(path);
        File file = new File(path);
        System.out.println(file.getParent());
        System.out.println(file.getAbsolutePath());

        String projectPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        File baseFile = new File(projectPath);
        String basePath = String.format("%s/upload", baseFile.getParent());
        try {
            File uploadDir = new File(basePath);
            if (!uploadDir.exists()) {
                boolean success = uploadDir.mkdirs();
                System.out.println(success);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

//        String basePath = path.substring(0, path.indexOf(":") + 1);
//        System.out.println(basePath);


//        String path = "E:\\git\\work\\app.jars";
//        File file = new File(path);
//        File[] files = file.listFiles();
//        Pattern p = Pattern.compile("-0.0.1-SNAPSHOT.jar$");
//        for (File f : files) {
//            if (f.getName().indexOf(".jar") > -1) {
//                // System.out.println("start java -jar " + f.getName());
//                Matcher m = p.matcher(f.getName());
//                System.out.print(m.replaceAll(" "));
//            }
//        }
    }
}
